]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: Destroy GjsContext before exit
authorPhilip Chimento <philip@endlessm.com>
Tue, 6 Dec 2016 01:31:08 +0000 (17:31 -0800)
committerPhilip Chimento <philip@endlessm.com>
Wed, 7 Dec 2016 19:34:15 +0000 (11:34 -0800)
This will be required in the upcoming version of GJS.

The reference count on ShellGlobal is 2 at this point, because JS holds a
reference due to the "window.global = Shell.Global.get()" line in
ui/environment.js. Therefore, destroy the GjsContext first, then unref
the ShellGlobal object.

Cleaning up ShellGlobal was previously only enabled behind a debug
environment variable, but it should be required now.

https://bugzilla.gnome.org/show_bug.cgi?id=775374

src/main.c
src/shell-global-private.h
src/shell-global.c

index 25d2778d05261307db6b303590a9f10ce17f5507..c88f04642b27430075c37a89761441ba28ce070e 100644 (file)
@@ -469,12 +469,9 @@ main (int argc, char **argv)
 
   ecode = meta_run ();
 
-  if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP"))
-    {
-      g_printerr ("Doing final cleanup...\n");
-      g_object_unref (shell_global_get ());
-    }
-
+  g_debug ("Doing final cleanup");
+  _shell_global_destroy_gjs_context (shell_global_get ());
+  g_object_unref (shell_global_get ());
   g_object_unref (sender);
 
   return ecode;
index 786719f5bfa6354300ca1ca6dd4906db1997de68..df53236aac54ea01718916891ff87aa13f793c7e 100644 (file)
@@ -11,6 +11,8 @@ void _shell_global_init            (const char *first_property_name,
 void _shell_global_set_plugin      (ShellGlobal  *global,
                                     MetaPlugin   *plugin);
 
+void        _shell_global_destroy_gjs_context (ShellGlobal  *global);
+
 GjsContext *_shell_global_get_gjs_context (ShellGlobal  *global);
 
 gboolean _shell_global_check_xdnd_event (ShellGlobal  *global,
index 6dda3526ac613e3a2700b1dbec737b357d8cf35f..3f9ee8d4fad57716acceabe5d046bab26956632b 100644 (file)
@@ -338,7 +338,7 @@ shell_global_finalize (GObject *object)
 {
   ShellGlobal *global = SHELL_GLOBAL (object);
 
-  g_object_unref (global->js_context);
+  g_clear_object (&global->js_context);
   g_object_unref (global->settings);
 
   the_object = NULL;
@@ -566,6 +566,20 @@ shell_global_get (void)
   return the_object;
 }
 
+/**
+ * _shell_global_destroy_gjs_context: (skip)
+ * @self: global object
+ *
+ * Destroys the GjsContext held by ShellGlobal, in order to break reference
+ * counting cycles. (The GjsContext holds a reference to ShellGlobal because
+ * it's available as window.global inside JS.)
+ */
+void
+_shell_global_destroy_gjs_context (ShellGlobal *self)
+{
+  g_clear_object (&self->js_context);
+}
+
 static guint32
 get_current_time_maybe_roundtrip (ShellGlobal *global)
 {